package com.thrblock.needle;

import geivcore.UesContext;
import geivcore.Uesi;
import geivcore.engineSys.io.DefaultKeyFactor;
import geivcore.engineSys.io.KeyFactor;
import geivcore.engineSys.io.KeyListener;

import java.awt.event.KeyEvent;

import com.thrblock.commoncwd.GCommonPool;
import com.thrblock.needle.bean.Flag;
import com.thrblock.needle.bean.Needle;
import com.thrblock.needle.bean.YarnBall;


public class NeedleInstance extends DefaultKeyFactor implements KeyListener{
	Uesi ues = UesContext.getCurrentContext();
	Flag flag = new Flag();
	YarnBall ball = new YarnBall();
	GCommonPool<Needle> needlePool = new GCommonPool<Needle>(48);
	public NeedleInstance() {
		for(int i = 0;i < 48;i++) {
			needlePool.addPoolable(new Needle());
		}
		this.setKeyListener(this);
		ues.pushKeyBoardIO(this);
	}
	public void runGame() {
		ball.enable();
		flag.enable();
	}
	@Override
	public void doKeyBord(KeyFactor whom, int keyCode, boolean ispressed) {
		if(ispressed) {
			if(keyCode == KeyEvent.VK_SPACE) {
				Needle needle = needlePool.getAvailable();
				needle.getUse(null);
				if(ball.acupuncture(needle)) {
					ball.clear();
				}
				flag.tear();
			} else if(keyCode == KeyEvent.VK_R) {
				ball.clear();
			}
		}
	}
}
